import {
	Component
} from 'react';
import {
	Tab,
	Button,
	Group,
	Boxs,
	Toast,
	Avatar,
	Dialog
} from 'saltui';
const {
	IconButton
} = Button;
const {
	HBox,
	Box
} = Boxs;
import AngleRight from 'salt-icon/lib/AngleRight';
import PageController from 'pages/home';
import {
	urlPrefix,
	URLS,
	nodataIcon,
	dictMap
} from '../../../app/variables';
import DB from '../../../app/db';
import PostPageItem from 'components/post_page_item';
let tabPage = '0';
export default class PageHome extends Component {

	constructor(props) {
		super(props);
		var token = document.getElementById("token").value;
		var context = document.getElementById("context").value;
		let winHeight = hasBottomTab == 1 ? getScrollHigh(1, 1, 1) : getScrollHigh(1, 1, 0);
		this.state = {
			winHeight: winHeight,
			urlPrev: context + '/api/m/plugin/attachment/mobile/viewImage?fid=',
			token : token,
			postInfo:{
				replyPostCount: 0,
				postCount: 0,
				collectionCount: 0,
				authorName: '',
				userPhotoPath: '',
				image:'',
			}
		}

		dd.biz.navigation.setTitle({
      		title: '论坛动态',
		    onSuccess: function (result) {},
     		onFail: function () {}
    	});
   	}

	//加载待我审核的帖子数量
	componentWillMount() {
		this.getIfReadAll();
		this.dislodgeActionSheet();
		Dialog.hide();
	}

	dislodgeActionSheet(){
      var u = navigator.userAgent;
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      if(isAndroid==true){
           document.addEventListener('backbutton', function(e) {
            $('.t-popup-mask').trigger('click');
            e.preventDefault();
           });
      }else if(isiOS==true){
          dd.biz.navigation.setLeft({
              control: true,//是否控制点击事件，true 控制，false 不控制， 默认false
              text: '',//控制显示文本，空字符串表示显示默认文本
              onSuccess : function(result) {
                $('.t-popup-mask').trigger('click');
                $('.t-popup-mask').trigger('click');
                backPage();
              },
              onFail : function(err) {}
          });
      }
    }

	getIfReadAll() {
		DB.ForumModuleAPI.getIfReadAll({})
		.then((content) => {
			this.setState({
				postInfo: content
			});
		}).catch((error) => {

		});
	}

	skipPage(field){
		if(field!='' && field!=undefined){
			location.hash = 'my/remind/' +  field;
		}
	}
	

	render() {
		let winHeightStyle = {
			height: this.state.winHeight
		};
		return (
			<div>
				<HBox vAlign="center" className="t-BCf t-PL16 t-PR16 t-PT10 t-PB10  t-FS16 t-PR">
					<HBox flex={1} vAlign="center" onClick={this.skipPage.bind(this,'1')}>
						<i className="iconfont icon-reply t-FCorange t-MR6 t-FS16"></i>
						<span className="t-omit">我回复的</span>
					</HBox>
					<Box>
						<AngleRight fill="#bbc3cd" width={20} />
					</Box>
				</HBox>
				<HBox vAlign="center" className="t-BCf t-PL16 t-PR16 t-PT10 t-PB10  t-FS16 t-PR">
					<HBox flex={1} vAlign="center" onClick={this.skipPage.bind(this,'2')}>
						<i className="iconfont icon-forum t-FCorange t-MR6 t-FS16"></i>
						<span className="t-omit">评论我的<i className={this.state.postInfo.contactMine?"iconfont icon-dotted t-PA":"t-DN"} style={{right:'20',top:'10',color:'#f14a4a',fontSize:'34px'}}></i></span>
					</HBox>
					<Box>
						<AngleRight fill="#bbc3cd" width={20} />
					</Box>
				</HBox>
				<HBox vAlign="center" className="t-BCf t-PL16 t-PR16 t-PT10 t-PB10  t-FS16 t-PR">
					<HBox flex={1} vAlign="center" onClick={this.skipPage.bind(this,'3')}>
						<i className="iconfont icon-link t-FCorange t-MR6 t-FS16"></i>
						<span className="t-omit">@我的<i className={this.state.postInfo.commentMine?"iconfont icon-dotted t-PA":"t-DN"} style={{right:'20',top:'10',color:'#f14a4a',fontSize:'34px'}}></i></span>
					</HBox>
					<Box>
						<AngleRight fill="#bbc3cd" width={20} />
					</Box>
				</HBox>
			</div>
	  );
  }
}